/***********************************************************************
    filename:   DaterBaseWindowManager.h
    created:    10/4/2012
    author:     4Ys

    purpose:    Defines class for Window Manager and Singleton objects in UI
*************************************************************************/
#ifndef _DaterWindowManager_h_
#define _DaterWindowManager_h_

#include <cassert>
#include "DaterBaseWindow.h"

template<typename T> class Singleton
{
	/*!
	\brief
		The core class Singleton, the parent of all managers.
	*/
protected:
	static T* ms_Singleton;

public:
		/* !
		\brief
			Construct the sample of class Singleton.
		*/
	Singleton( void )
	{
		assert( !ms_Singleton );
		ms_Singleton = static_cast<T*>(this);
	}
	
		/* !
		\brief
			Destructor of class Singleton.
		*/
	~Singleton( void )
		{  assert( ms_Singleton );  ms_Singleton = 0;  }
	
		/* !
		\brief
			Get a certain Singleton.
		*/		
	static T& getSingleton( void )
		{  assert( ms_Singleton );  return ( *ms_Singleton );  }
		
		/*
		\brief
			Get a pointer to a certain Singleton.
		*/
	static T* getSingletonPtr( void )
		{  return ( ms_Singleton );  }

private:
	Singleton& operator=(const Singleton&) { return this; }
	
		/* !
		\brief
			Construct the sample of class Singleton.
			
		\param Singleton
		*/
	Singleton(const Singleton&) {}
};

class BaseWindowManager : public Singleton < BaseWindowManager>
{
	/*!
	\brief
		Defines the managers of windows.
	*/
public:
		/* !
		\brief
			Construct the sample of class BaseWindowManager.
		*/
	BaseWindowManager(void);

		/* !
		\brief
			Destructor of class BaseWindowManager.
		*/
	~BaseWindowManager(void);

		/* !
		\brief
			Add base window.
		*/
	void addBaseWindow(BaseWindow*);

		/* !
		\brief
			Destroy base windows with a name.
			
		\param name
			The name as a key to destroy.
		*/
	void destroyBaseWindow(const std::string& name);

		/* !
		\brief
			Destroy base windows with a name.
		*/
	void destroyBaseWindow(BaseWindow*);

		/* !
		\brief
			Get base windows with name.
			
		\param name
			The name as a key to get.
		*/
	BaseWindow* getWindow(const std::string& name);

		/* !
		\brief
			Judge whether the base window with a certain name exist.
			
		\param name
			The name as a key to judge.
		*/
	bool isBaseWindowPresent(const std::string& name);

		/* !
		\brief
			Destroy all base windows.
		*/
	void destroyAllBaseWindows(void);

private:

		//! A map contains base windows of the process.
	typedef std::map<std::string, BaseWindow*> BaseWindowRegistry;

		//! The BaseWindowRegistry.
	BaseWindowRegistry _baseWindowRegistry;
};

#endif